<template>
	<view class="content">
		<u-navbar fixed title="分析审批" :autoBack="true" fixed></u-navbar>
		<view class="top-content">
			<view class="select-time" @click="showCalendar = true">
				<view style="margin-right: 12rpx">
					{{ eventDateStr ? eventDateStr : '选择时间' }}
				</view>
				<u-icon name="arrow-down-fill" color="#bbb" size="20"></u-icon>
			</view>
			<view class="select-status" @click="showPicker = true">
				<view style="margin-right: 12rpx">
					{{ eventStatusStr ? eventStatusStr : '上报状态' }}
				</view>
				<u-icon name="arrow-down-fill" color="#bbb" size="20"></u-icon>
			</view>
		</view>
		<view class="inner-content">
			<view class="list-content">
				<u-list @scrolltolower="scrolltolower" style="margin-top: 24rpx;" height="90vh">
					<u-list-item v-for="(item, index) in listData" :key="item.id">
						<view class="month-content">
							{{ item.month }}
						</view>
						<view v-for="(item2, index2) in item.children" :key="item2.id" class="list-item"
							@click="toCheck(item2)">
							<view class="item-content">
								<view class="left-content">
									<view class="title">
										{{ item2.title }}
									</view>
								</view>
								<view class="right-content">
									<u-tag :text="item2.status" type="warning"></u-tag>
								</view>
							</view>
							<view class="item-content">
								<view class="left-content">
									填写日期：{{ item2.date1 }}
								</view>
								<view class="right-content">
									上报日期：{{ item2.date2 }}
								</view>
							</view>
						</view>
					</u-list-item>
					<u-list-item style="margin-top: 12px;">
						<u-loadmore v-if="listData.length > 0" :status="status" :loading-text="loadingText"
							:loadmore-text="loadmoreText" :nomore-text="nomoreText" />
						<u-empty v-else marginTop="520rpx"
							icon="https://www.scyanuoedu.com/upload/images/20230728104453.png" width="90" textSize="18"
							text="这里也空空如也~">
						</u-empty>
					</u-list-item>
				</u-list>
			</view>
			<u-picker :show="showPicker" :columns="columns" keyName="label" @confirm="handlePickerConfirm"></u-picker>
			<u-calendar :show="showCalendar" mode="range" @confirm="handleCalendarConfirm"></u-calendar>
		</view>
	</view>
</template>

<script>
	import {
		getMsgList
	} from '@/api/message'
	import moment from 'moment'
	export default {
		data() {
			return {
				listData: [{
					id: 1,
					month: "4月",
					children: [{
						id: 100,
						title: "手术事件（123456789）",
						status: "已上报",
						date1: "2025-04-05",
						date2: "2025-04-02",
					}, {
						id: 200,
						title: "手术事件（123456789）",
						status: "已完结",
						date1: "2025-04-05",
						date2: "2025-04-02",
					}, {
						id: 300,
						title: "手术事件（123456789）",
						status: "草稿",
						date1: "2025-04-05",
						date2: "2025-04-02",
					}, {
						id: 400,
						title: "手术事件（123456789）",
						status: "已上报",
						date1: "2025-04-05",
						date2: "2025-04-02",
					}]
				}, {
					id: 2,
					month: "5月",
					children: [{
						id: 500,
						title: "手术事件（123456789）",
						status: "已上报",
						date1: "2025-04-05",
						date2: "2025-04-02",
					}, {
						id: 600,
						title: "手术事件（123456789）",
						status: "已上报",
						date1: "2025-04-05",
						date2: "2025-04-02",
					}, {
						id: 700,
						title: "手术事件（123456789）",
						status: "已上报",
						date1: "2025-04-05",
						date2: "2025-04-02",
					}, {
						id: 800,
						title: "手术事件（123456789）",
						status: "已上报",
						date1: "2025-04-05",
						date2: "2025-04-02",
					}]
				}, {
					id: 3,
					month: "6月",
					children: [{
						id: 900,
						title: "手术事件（123456789）",
						status: "已上报",
						date1: "2025-04-05",
						date2: "2025-04-02",
					}, {
						id: 901,
						title: "手术事件（123456789）",
						status: "已上报",
						date1: "2025-04-05",
						date2: "2025-04-02",
					}, {
						id: 902,
						title: "手术事件（123456789）",
						status: "已上报",
						date1: "2025-04-05",
						date2: "2025-04-02",
					}, {
						id: 903,
						title: "手术事件（123456789）",
						status: "已上报",
						date1: "2025-04-05",
						date2: "2025-04-02",
					}]
				}],
				page: 1,
				total: 0,
				status: 'loadmore',
				loadingText: '加载中',
				loadmoreText: '',
				nomoreText: '已显示全部',
				showPicker: false,
				showCalendar: false,
				columns: [
					[{
						label: '待上报',
						id: 2021
					}, {
						label: '已上报',
						id: 804
					}],
				],
				eventDate: [],
				eventDateStr: "",
				eventStatusStr: "",
				eventStatusCode: "",
			}
		},
		onShow() {
			// this.getListData(1)
		},
		methods: {
			moment,
			scrolltolower() {
				if (this.listData.length < this.total) {
					this.page += 1
					this.getListData(this.page)
				} else {
					this.status = 'nomore'
				}
			},
			//获取消息列表
			getListData(page) {
				const userId = this.$store.getters?.userInfo?.id
				this.status = 'loading'
				if (page === 1) {
					this.page = 1
					this.listData = []
				}
				getMsgList(userId, {
					page,
					page_size: 20
				}).then(res => {
					console.log(res)
					this.listData = [...this.listData, ...res.data.data]
					this.total = res.data.total
				}).finally(() => {
					if (this.listData.length < this.total) {
						this.status = 'loadmore'
					} else {
						this.status = 'nomore'
					}
				})
			},
			//去查看
			toCheck(data) {
				uni.navigateTo({
					url: "/pages/home/components/analyseDetail?id=" + data.id
				})
			},
			handlePickerConfirm(e) {
				const value = e.value[0]
				this.eventStatusStr = value.label
				this.eventStatusCode = value.value
				this.showPicker = false;
			},
			handleCalendarConfirm(e) {
				console.log(e);
				const len = e.length
				this.eventDate = [e[0], e[len - 1]]
				this.eventDateStr = `${e[0]} ~ ${e[1]}`
				this.showCalendar = false;
			}

		}
	}
</script>

<style scoped lang="scss">
	.content {
		padding-top: 120rpx;
		padding-bottom: 48rpx;
		background-color: #f3f4f5;

		.top-content {
			display: flex;
			justify-content: space-between;
			background-color: #fff;
			margin: 0 48rpx;
			padding: 24rpx;
			border-radius: 12rpx;

			.select-time,
			.select-status {
				display: flex;
				align-items: center;
				font-size: 30rpx;
			}
		}

		.month-content {
			color: #2979ff;
		}

		.inner-content {
			margin: 0 24rpx;

			.list-item {
				padding: 24rpx;
				margin: 24rpx;
				background-color: #fff;
				border-radius: 12rpx;
				font-size: 28rpx;

				.item-content {
					font-color: #101010;
					display: flex;
					justify-content: space-between;
					margin-bottom: 12rpx;

					.title {
						color: #000;
					}

					.left-content,
					.right-content {
						color: #bbb;
					}
				}
			}
		}
	}
</style>